<template>
  <div>
    <div v-if="!isShowDetail">
      <jxf-titletip :title="title" @refreshPage="refreshFuc"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="供应商账号:" prop="telphone">
            <el-input v-model.trim="searchInfo.telphone" clearable ref="input-telphone" @keyup.enter.native="enterNextInput('enterpriseName')"></el-input>
          </el-form-item>
          <el-form-item label="企业名称:" prop="enterpriseName">
            <el-input v-model.trim="searchInfo.enterpriseName" clearable ref="input-enterpriseName" @keyup.enter.native="enterNextInput('name')"></el-input>
          </el-form-item>
          <el-form-item label="门店名称:" prop="name">
            <el-input v-model.trim="searchInfo.name" clearable ref="input-name" @keyup.enter.native="enterNextInput('salesmanName')"></el-input>
          </el-form-item>
          <el-form-item label="审核状态:" prop="status">
            <el-select v-model="searchInfo.status" clearable placeholder="全部">
              <el-option label="待审核" value="0"></el-option>
              <!--<el-option label="审核通过" value="1"></el-option>-->
              <el-option label="审核驳回" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属分公司:" prop="agentId">
            <el-select v-model="searchInfo.agentId" clearable filterable placeholder="全部" @focus="getBranchList">
              <el-option :label="agents.userName" :value="agents.id" v-for="(agents, index) in branchList" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务员:" prop="salesmanName">
            <el-input v-model.trim="searchInfo.salesmanName" clearable ref="input-salesmanName" @keyup.enter.native="onSearch"></el-input>
          </el-form-item>
          <jxf-Date label="创建时间:" :startTime.sync="searchInfo.createTimeStart" :endTime.sync="searchInfo.createTimeEnd" startTimeProp="createTimeStart" endTimeProp="createTimeEnd"></jxf-Date>
          <jxf-Date label="审核时间:" :startTime.sync="searchInfo.auditTimeStart" :endTime.sync="searchInfo.auditTimeEnd" startTimeProp="auditTimeStart" endTimeProp="auditTimeEnd"></jxf-Date>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportExcel" :loading="isSuccess">导出为Excel</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="auditTime" slot-scope="supplier">
            <div>{{supplier.row.auditTime ? FormatDate.timeFormat(supplier.row.auditTime) : ""}}</div>
          </template>
          <template slot="createTime" slot-scope="supplier">
            <div>{{supplier.row.createTime ? FormatDate.timeFormat(supplier.row.createTime) : ""}}</div>
          </template>
          <template slot="status" slot-scope="supplier">
            <div v-if="supplier.row.status == 0">待审核</div>
            <div v-if="supplier.row.status == 1">审核通过</div>
            <div v-if="supplier.row.status == 2">审核驳回</div>
          </template>
          <template slot="operation" slot-scope="supplier">
            <el-button type="text" @click="watchDetail('1', supplier.row)" v-if="supplier.row.status === 2 || supplier.row.status === 1">查看详情</el-button>
            <el-button type="text" @click="watchDetail('0', supplier.row)" v-else class="c-red">去审核</el-button>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
    <SupplerReview v-else :title="subTitle" @goBack="goBack" :dataInfo="subDataInfo" @goPrewView="goPrewView" @fresh="fresh"></SupplerReview>
  </div>
</template>

<script>
  import SupplerReview from './components/SupplerReview'
  import formatMoney from '@/assets/js/formatMoney'
  import FormatDate from '@/assets/js/formatDate'
    export default {
        name: "SupplierAuditList",
        components: { SupplerReview },
        data() {
          return {
            title: "供应商审核列表",
            isShowDetail: false,
            searchInfo: {
              telphone: "",
              enterpriseName: "",
              name: "",
              status: "",
              agentId: "",
              salesmanName: "",
              createTimeStart: "",
              createTimeEnd: "",
              auditTimeStart: "",
              auditTimeEnd: ""
            },
            FormatDate: FormatDate,
            subTitle: "",
            branchList: [],
            subDataInfo: {},
            isSuccess: false,
            dataTable: {
              border:true,
              loading:false,
              hasSelect:false,
              hasOperation:false,
              tr: [
                // {
                //   id: '1',
                //   label: '编号',
                //   fixed: "left",
                //   prop: 'id'
                // },
                {
                  id: '2',
                  minWidth: '100',
                  label: '供应商账号',
                  fixed: "left",
                  prop: 'telphone'
                },
                {
                  id: '3',
                  minWidth: '140',
                  label: '供应商企业名称',
                  prop: 'enterpriseName'
                },
                {
                  id: '4',
                  minWidth: '140',
                  label: '供应商门店名称',
                  prop: 'name'
                },
                {
                  id: '5',
                  label: '经营行业',
                  prop: 'businessIndustrys'
                },
                {
                  id: '6',
                  minWidth: '100',
                  label: '所属分公司',
                  prop: 'agentName'
                },
                {
                  id: '7',
                  minWidth: '100',
                  label: '对接业务员',
                  prop: 'salesmanName'
                },
                {
                  id: '8',
                  label: '创建时间',
                  show: 'template',
                  width: '160',
                  prop: 'createTime'
                },
                {
                  id: '9',
                  label: '审核状态',
                  show: 'template',
                  prop: 'status'
                },
                {
                  id: '10',
                  label: '审核时间',
                  show: 'template',
                  width: '160',
                  prop: 'auditTime'
                },
                {
                  id: '11',
                  label: '操作',
                  show: 'template',
                  fixed: "right",
                  minWidth: "80",
                  prop: 'operation'
                }
              ],
              operation: [],
              data: []
            },
            pageTotal:0,
            pageSize:10,
            currentPage:1
          }
        },
        methods: {
          fresh() {
            this.getData()
          },
          // 返回当前页面
          goPrewView() {
            this.isShowDetail = false
            this.getData()
          },
          // 导出
          exportExcel() {
            this.isSuccess = true;
            let data = {
              ...this.searchInfo
            }
            ajax.export(apis.user.exportSupplierReviewExcel, data).then((res) => {
              this.isSuccess = false;
              if(res.code) {
                if(res.code === "10000000") {

                } else {
                  this.$message.error(res.message)
                }
              }
            })
          },
          getData() {
            this.dataTable.loading = true
            let data = {
              ...this.searchInfo,
              pageNum: this.currentPage,
              pageSize: this.pageSize
            };
            ajax.post(apis.user.supplierAuditingList, data).then(res => {
              if(res.code === '10000000') {
                this.dataTable.data = res.data ? res.data.dataList : [];
                this.pageTotal = res.data ? res.data.total : 0;
              } else {
                this.$message.error(res.message)
              }
              this.dataTable.loading = false
            })
          },
          refreshFuc() {
            this.resetForm('searchInfo')
            this.pageSize = 10;
            this.currentPage = 1;
            this.getData()
          },
          enterNextInput(inputName) {
            this.$refs["input-" + inputName].focus();
          },
          onSearch() {
            this.dataTable.data = this.getData(this.searchInfo)
            this.dataTable.loading = false
          },
          resetForm(formName) {
            this.$refs[formName].resetFields();
          },
          // 切换页面
          currentPageChange(pageNo) {
            this.currentPage = pageNo
            this.getData()
          },
          // 切换页面条数
          pageSizeChange(pageNo) {
            this.pageSize = pageNo
            this.getData()
          },
          // 获取分公司
          getBranchList() {
            let data = {
              userType: '2'
            }
            ajax.post(apis.user.getBranchList, data).then(res => {
              if(res.code == '10000000') {
                this.branchList = res.data.dataList;
              } else {
                this.$message.error(res.message)
              }
            })
          },
          // 查看详情
          watchDetail(type, obj) {
            switch (type) {
              case '0':
                this.subTitle = "去审核";
                let data = {
                  id: obj.id,
                  statusNum: 1,
                  status: obj.status,
                  userId: obj.userId
                };
                ajax.post(apis.user.getSupplierDetail, data).then(res => {
                  if(res.code === "10000000") {
                    this.subDataInfo = {
                      status: 0,
                      page: 0,
                      accountStatus: null,
                      businessId: res.data.supplierPcVo.businessId,
                      identityCard: {
                        value: res.data.supplierPcVo.identityCard ? res.data.supplierPcVo.identityCard : "",
                        isEdit: false
                      },
                      license: {
                        value: res.data.supplierPcVo.license ? res.data.supplierPcVo.license : "",
                        isEdit: false
                      },
                      cityId: res.data.supplierPcVo.cityId,
                      otherQualification: {
                        value: res.data.supplierPcVo.otherQualification ? res.data.supplierPcVo.otherQualification : "",
                        isEdit: false
                      },
                      id: res.data.supplierPcVo.id,
                      enterpriseAuthId: res.data.supplierPcVo.enterpriseAuthId,
                      reTimeStart: res.data.supplierPcVo.reTimeStart,
                      reTimeEnd: res.data.supplierPcVo.reTimeEnd,
                      identityCardStart: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[0] : "",
                      identityCardEnd: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[1] : "",
                      deliveryIds: res.data.supplierPcVo.deliveryIds,
                      typeId: res.data.supplierPcVo.typeId,
                      ismain: res.data.supplierPcVo.ismain,
                      userId: res.data.supplierPcVo.userId,
                      supplierInfo: [
                        {
                          label: "*门店/logo图片",
                          value: res.data.supplierPcVo.logo,
                          type: 'logo',
                          isEdit: false
                        }, {
                          label: "起批金额（元)",
                          value: res.data.supplierPcVo.upMoney,
                          type: 'batchMoney',
                          isEdit: false
                        }, {
                          label: "供应商主体账号",
                          value: res.data.supplierPcVo.telphone,
                          type: "subjectAccount"
                        }, {
                          label: "起送金额（元）",
                          value: res.data.supplierPcVo.taMoney,
                          type: 'startMoney',
                          isEdit: false
                        }, {
                          label: "*企业名称",
                          value: res.data.supplierPcVo.enterpriseName,
                          type: 'companyName',
                          isEdit: false
                        }, {
                          label: "是否开启甩单",
                          value: res.data.supplierPcVo.isFling ? res.data.supplierPcVo.isFling.toString() : res.data.supplierPcVo.isFling ,
                          type: 'isOrder',
                          isEdit: false
                        }, {
                          label: "*门店名称",
                          value: res.data.supplierPcVo.name,
                          type: 'storeName',
                          isEdit: false
                        }, {
                          label: "备货时长",
                          value: res.data.supplierPcVo.stockTime,
                          type: 'stockTime',
                          isEdit: false
                        }, {
                          label: "*门店地址",
                          value: res.data.supplierPcVo.storeAddress,
                          type: 'storeAddress',
                          isEdit: false
                        }, {
                          label: "接单时间",
                          value: "",
                          type: 'orderTime',
                          isEdit: false
                        }, {
                          label: "*配送区域",
                          value: res.data.supplierPcVo.deliveryArea,
                          type: 'deliveryArea',
                          isEdit: false
                        }, {
                          label: "账号状态",
                          value: res.data.supplierPcVo.userStatus,
                          type: 'accountStatus',
                          isEdit: false
                        }, {
                          label: "客服电话",
                          value: res.data.supplierPcVo.contact,
                          type: 'consumerHotline',
                          isEdit: false
                        }, {
                          label: "所属分公司",
                          value: res.data.supplierPcVo.agentName,
                          type: "Branch"
                        }, {
                          label: "*经营行业",
                          value: res.data.supplierPcVo.businessIndustrys,
                          type: 'operatingIndustry',
                          isEdit: false
                        }, {
                          label: "对接业务员",
                          value: res.data.supplierPcVo.salesmanName,
                          type: 'dockingSalesman'
                        }, {
                          label: "*社会代码",
                          value: res.data.supplierPcVo.creditCode,
                          type: "creditCode",
                          isEdit: false
                        }, {
                          label: "所属渠道商",
                          value: res.data.supplierPcVo.channelDealerName,
                          type: 'dockingChannel'
                        }, {
                          label: "*定位地址",
                          value: res.data.supplierPcVo.sadress
                        }, {
                          label: '',
                          value: ''
                        }
                      ],
                      otherInfo: [{
                        label: "*注册主体人的名称",
                        value: res.data.supplierPcVo.registrantName,
                        type: "subjectPerson",
                        isEdit: false
                      }, {
                        label: "*注册主体人身份证号码",
                        value: res.data.supplierPcVo.registrantIdNum,
                        type: "registeredIDNumber",
                        isEdit: false
                      }, {
                        label: "*法人名称",
                        value: res.data.supplierPcVo.legalName,
                        type: "legalName",
                        isEdit: false
                      }, {
                        label: "*法人身份证号码",
                        value: res.data.supplierPcVo.idNumber,
                        type: "identityCard",
                        isEdit: false
                      }, {
                        label: "*法人身份证有效期",
                        value: res.data.supplierPcVo.certificateValidity,
                        type: "certificateValidity",
                        isEdit: false
                      }, {
                        label: "入驻时间",
                        value: res.data.supplierPcVo.auditTime,
                        type: "auditTime"
                      }, {
                        label: "南京银行子账号",
                        value: "",
                        type: "legalIDNumber"
                      }, {
                        label: "华夏银行子账号",
                        value: "",
                        type: "legalIDNumber"
                      }, {
                        label: "预留银行卡所属行",
                        value: "",
                        type: "legalIDNumber",
                        isEdit: false
                      }, {
                        label: "银行卡卡号",
                        value: res.data.supplierPcVo.cardNo,
                        type: "cardNo"
                      }],
                      originalinfo: {

                      },

                    };
                    this.isShowDetail = true;
                  } else {
                    this.$message.error(res.message)
                  }
                })
                break;
              case '1':
                this.subTitle = "查看详情";
                let subData = {
                  id: obj.id,
                  statusNum: 2,
                  status: obj.status,
                  userId: obj.userId
                };

                ajax.post(apis.user.getSupplierDetail, subData).then(res => {
                  if(res.code === "10000000") {
                    this.subDataInfo = {
                      status: 1,
                      page: 0,
                      accountStatus: null,
                      businessId: res.data.supplierPcVo.businessId,
                      identityCard: {
                        value: res.data.supplierPcVo.identityCard ? res.data.supplierPcVo.identityCard : "",
                        isEdit: false
                      },
                      license: {
                        value: res.data.supplierPcVo.license ? res.data.supplierPcVo.license : "",
                        isEdit: false
                      },
                      cityId: res.data.supplierPcVo.cityId,
                      otherQualification: {
                        value: res.data.supplierPcVo.otherQualification ? res.data.supplierPcVo.otherQualification : "",
                        isEdit: false
                      },
                      id: res.data.supplierPcVo.id,
                      enterpriseAuthId: res.data.supplierPcVo.enterpriseAuthId,
                      reTimeStart: res.data.supplierPcVo.reTimeStart,
                      reTimeEnd: res.data.supplierPcVo.reTimeEnd,
                      identityCardStart: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[0] : "",
                      identityCardEnd: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[1] : "",
                      deliveryIds: res.data.supplierPcVo.deliveryIds,
                      typeId: res.data.supplierPcVo.typeId,
                      ismain: res.data.supplierPcVo.ismain,
                      userId: res.data.supplierPcVo.userId,
                      supplierInfo: [
                        {
                          label: "门店/logo图片",
                          value: res.data.supplierPcVo.logo,
                          type: 'logo'
                        }, {
                          label: "起批金额（元)",
                          value: res.data.supplierPcVo.upMoney,
                          type: 'batchMoney'
                        }, {
                          label: "供应商主体账号",
                          value: res.data.supplierPcVo.telphone,
                          type: "subjectAccount"
                        }, {
                          label: "起送金额（元）",
                          value: res.data.supplierPcVo.taMoney,
                          type: 'startMoney'
                        }, {
                          label: "*企业名称",
                          value: res.data.supplierPcVo.enterpriseName,
                          type: 'companyName'
                        }, {
                          label: "是否开启甩单",
                          value: res.data.supplierPcVo.isFling,
                          type: 'isOrder'
                        }, {
                          label: "*门店名称",
                          value: res.data.supplierPcVo.name,
                          type: 'storeName',
                          isEdit: false
                        }, {
                          label: "备货时长",
                          value: res.data.supplierPcVo.stockTime,
                          type: 'stockTime'
                        }, {
                          label: "*门店地址",
                          value: res.data.supplierPcVo.storeAddress,
                          type: 'storeAddress',
                          isEdit: false
                        }, {
                          label: "接单时间",
                          value: "",
                          type: 'orderTime',
                          isEdit: false
                        }, {
                          label: "*配送区域",
                          value: res.data.supplierPcVo.deliveryArea,
                          type: 'deliveryArea'
                        }, {
                          label: "账号状态",
                          value: res.data.supplierPcVo.userStatus,
                          type: 'accountStatus'
                        }, {
                          label: "客服电话",
                          value: res.data.supplierPcVo.contact,
                          type: 'consumerHotline'
                        }, {
                          label: "所属分公司",
                          value: res.data.supplierPcVo.agentName,
                          type: "Branch"
                        }, {
                          label: "*经营行业",
                          value: res.data.supplierPcVo.businessIndustrys,
                          type: 'operatingIndustry'
                        }, {
                          label: "对接业务员",
                          value: res.data.supplierPcVo.salesmanName,
                          type: 'dockingSalesman'
                        }, {
                          label: "*社会代码",
                          value: res.data.supplierPcVo.creditCode,
                          type: "creditCode"
                        }, {
                          label: "所属渠道商",
                          value: res.data.supplierPcVo.channelDealerName,
                          type: 'dockingChannel'
                        }, {
                          label: "*定位地址",
                          value: res.data.supplierPcVo.sadress
                        }, {
                          label: '',
                          value: ''
                        }
                      ],
                      recording: [
                        {
                          label: "审核人",
                          value: res.data.supplyAuditPcVo.userName,
                          type: "userName"
                        }, {
                          label: "审核时间",
                          value: res.data.supplyAuditPcVo.createTime,
                          type: "createTime"
                        }, {
                          label: "审核结果",
                          value: res.data.supplyAuditPcVo.result,
                          type: "result"
                        }, {
                          label: "审核备注",
                          value: res.data.supplyAuditPcVo.content,
                          type: "content"
                        }
                      ],
                      otherInfo: [{
                        label: "*注册主体人的名称",
                        value: res.data.supplierPcVo.registrantName,
                        type: "subjectPerson",
                        isEdit: false
                      }, {
                        label: "*注册主体人身份证号码",
                        value: res.data.supplierPcVo.registrantIdNum,
                        type: "registeredIDNumber"
                      }, {
                        label: "*法人名称",
                        value: res.data.supplierPcVo.legalName,
                        type: "legalName"
                      }, {
                        label: "*法人身份证号码",
                        value: res.data.supplierPcVo.idNumber,
                        type: "identityCard"
                      }, {
                        label: "*法人身份证有效期",
                        value: res.data.supplierPcVo.certificateValidity,
                        type: "certificateValidity"
                      }, {
                        label: "入驻时间",
                        value: res.data.supplierPcVo.auditTime,
                        type: "auditTime"
                      }, {
                        label: "南京银行子账号",
                        value: "",
                        type: "legalIDNumber"
                      }, {
                        label: "华夏银行子账号",
                        value: "",
                        type: "legalIDNumber"
                      }, {
                        label: "预留银行卡所属行",
                        value: "",
                        type: "legalIDNumber"
                      }, {
                        label: "银行卡卡号",
                        value: res.data.supplierPcVo.cardNo,
                        type: "cardNo"
                      }],
                      originalinfo: {

                      },

                    };
                    this.isShowDetail = true;
                  } else {
                    this.$message.error(res.message)
                  }
                })
                break;
              default:
                return;
            }
          },
          // 详情返回上一页
          goBack() {
            this.getData()
            this.isShowDetail = false;
          }
        },
        created() {
          this.onSearch()
        }
    }
</script>

<style lang="scss" scoped>

</style>
